package net.cityside.summer.test;

import java.io.IOException;
import java.sql.Connection;

import org.dbunit.DatabaseUnitException;
import org.dbunit.database.DatabaseConnection;
import org.dbunit.database.IDatabaseConnection;
import org.dbunit.dataset.DataSetException;
import org.dbunit.dataset.excel.XlsDataSet;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.core.io.ClassPathResource;

public class DbTester {

	public static XlsDataSet getDataSetFromXls(String filename)
			throws DataSetException, IOException {
		ClassPathResource classPathResource = new ClassPathResource(filename);
		XlsDataSet dataSet = new XlsDataSet(classPathResource.getFile());
		return dataSet;
	}

	public static Connection getConnection(SqlSessionTemplate ssTemplate) {
		return ssTemplate.getConnection();
	}

	public static IDatabaseConnection getDatabaseConnection(Connection conn)
			throws DatabaseUnitException {
		return new DatabaseConnection(conn);
	}

	public static IDatabaseConnection getDatabaseConnection(
			SqlSessionTemplate ssTemplate) throws DatabaseUnitException {
		return new DatabaseConnection(getConnection(ssTemplate));
	}

}
